with Ada.Assertions; use Ada.Assertions;


separate(Test_Headers_Parser)

--
-- test parse headers
--
--       retrieve any numeric content-length header value present
--

procedure Test_Parse_Headers_Get_Content_Length
is

   --
   -- obtain headers, separating from content
   --
   --    call the 'Read_Test_Data_File' defined by Test_Parse_Headers
   --


   Headers_Found : constant String := Headers_Parser_Pkg.Parse_Headers(

         Read_Test_Data_File );


   --
   -- expected numeric value for the 'Content-Length: xxx..' header
   --

   TEST_HEADER_VALUE : constant := 218;


   --
   -- bogus String test
   --

   BOGUS_STR : constant String :=  "Vary: Accept-Encoding"
     & Ascii.LF & Ascii.CR
     & "Connection: close"
     & Ascii.LF & Ascii.CR;


   --
   -- temporary variable for retention of content-length
   --

   Length_Found : Natural := 0;


begin

   --
   -- compare to known length for the test String containing header
   --

   Assert( Content_Length_Headers_Pkg.Get_Length( Headers_Found )

           = TEST_HEADER_VALUE,

          "Content-Length value varies from expected" );


   --
   -- values are cached, must be cleared before reuse with new argument
   --

   Headers_Parser_Pkg.Clear;


   --
   -- test with bogus String to ensure zero is returned, std-err message
   --    displayed
   --

   Length_Found := Content_Length_Headers_Pkg.Get_Length( BOGUS_STR );

   Assert( Length_Found = 0,

           "Bogus content test. Expected zero for content-length but"
           & " received non-zero value: "
           & Natural'Image( Length_Found ));


end Test_Parse_Headers_Get_Content_Length;

